<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // function getName() {
    //     setTimeout(() => {
    //         return '张三';
    //     }, 2000); //2s
    // }
    // var name = getName(); //10ms
    // console.log(name);
    let fag = true;
    let promise = new Promise((resolve, reject) => {
        var user = {}
        if (fag) {
            setTimeout(() => {
                user = {
                    name: 'zhangsan',
                    age: 18
                }
                resolve(user);
            }, 2000)
        } else {
            reject('失败');
        }
    })
    promise.then((res) => {
        console.log(res);
    }).catch((err) => {
        console.log(err);
    })
</script>

</html>